//写入cookie
const set = (name, value, { maxAge, domain, path, secure } = {}) => {
  let cookieText = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`
  if (typeof maxAge === 'number') {
    console.log(1);
    cookieText += `; max-age=${maxAge}`;
    // console.log(cookieText);
  }
  if (domain) {
    cookieText += `; domain=${domain}`;
  }
  if (path) {
    cookieText += `; path=${path}`;
  }
  if (secure) {
    cookieText += `; secure`;
  }

  document.cookie = cookieText;
};
const get=name=>{
  name=`${encodeURIComponent(name)}`;
  const cookies=document.cookie.split(';')
  for(const item of cookies){
    const [cookieName,cookieValue]=item.split('=')
    if(cookieName===name){
      console.log(1);
      return decodeURIComponent(cookieValue)
      console.log(cookieValue);
    }
  }
  
  return;
}
const remove=(name,{domain,path}={})=>{
  set(name,'',{domain,path,maxAge:-1})
}
export { set,get,remove}